<!doctype html>



  


<html class="theme-next mist use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Blog," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="说明：介绍建立个人blog站点的主要流程，租用服务器、域名，使用hexo、github进行实现。">
<meta name="keywords" content="Blog">
<meta property="og:type" content="article">
<meta property="og:title" content="搭建个人博客站点(2)-托管到公网服务器">
<meta property="og:url" content="http://bebetter.site/2016/08/08/Blog/搭建个人博客站点2-托管到公网服务器/index.html">
<meta property="og:site_name" content="gatewayzy">
<meta property="og:description" content="说明：介绍建立个人blog站点的主要流程，租用服务器、域名，使用hexo、github进行实现。">
<meta property="og:updated_time" content="2016-08-08T13:36:13.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="搭建个人博客站点(2)-托管到公网服务器">
<meta name="twitter:description" content="说明：介绍建立个人blog站点的主要流程，租用服务器、域名，使用hexo、github进行实现。">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Mist',
    sidebar: {"position":"right","display":"always"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="http://bebetter.site/2016/08/08/Blog/搭建个人博客站点2-托管到公网服务器/"/>

  <title> 搭建个人博客站点(2)-托管到公网服务器 | gatewayzy </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-right page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">gatewayzy</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">blog of gatewayzy</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                搭建个人博客站点(2)-托管到公网服务器
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-08-08T21:36:04+08:00" content="2016-08-08">
              2016-08-08
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/Blog/" itemprop="url" rel="index">
                    <span itemprop="name">Blog</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><strong>说明：</strong>介绍建立个人blog站点的主要流程，租用服务器、域名，使用hexo、github进行实现。<br><a id="more"></a></p>
<h2 id="参考文章"><a href="#参考文章" class="headerlink" title="参考文章"></a>参考文章</h2><hr>
<p>建博客还可参阅之前的文章《搭建个人博客站点-1》，在那篇文章中使用了github pages和hexo进行搭建，文中对宏观的建站流程进行了说明讲解。</p>
<h2 id="流程说明"><a href="#流程说明" class="headerlink" title="流程说明"></a>流程说明</h2><hr>
<ul>
<li>租用服务器、域名。</li>
<li>在服务器上部署网站。</li>
</ul>
<p>服务器上部署网站的方法很多，本文采用方法如下：</p>
<ul>
<li>用hexo建站。</li>
<li>用nginx代理hexo的网站。</li>
</ul>
<h3 id="服务器、域名、域名解析"><a href="#服务器、域名、域名解析" class="headerlink" title="服务器、域名、域名解析"></a>服务器、域名、域名解析</h3><hr>
<ul>
<li>租用阿里云的服务器EMC服务，选用Ubuntu版本，IP记为10.10.10.10。</li>
<li>使用参考文章中的域名。</li>
<li>使用参考文章中的DNSPod添加域名解析如下。</li>
</ul>
<table>
<thead>
<tr>
<th>主机记录</th>
<th>记录类型</th>
<th>记录值</th>
</tr>
</thead>
<tbody>
<tr>
<td>*</td>
<td>A</td>
<td>10.10.10.10</td>
</tr>
<tr>
<td>@</td>
<td>A</td>
<td>10.10.10.10</td>
</tr>
</tbody>
</table>
<p>可以将其他不用的解析规则暂停。</p>
<h3 id="hexo部署网站"><a href="#hexo部署网站" class="headerlink" title="hexo部署网站"></a>hexo部署网站</h3><hr>
<ul>
<li>仿照参考文章中的方法，安装git，nodejs，hexo。发布hexo。</li>
<li>可以编写脚本进行自启动运行<ul>
<li>比如在windows下，编写bat脚本程序如下</li>
<li>添加自启动的计划任务即可</li>
<li>如果需要关闭hexo程序，可以通过任务管理器关闭nodejs的进程。</li>
</ul>
</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">chdir /d C:</div><div class="line">cd C:\Project\Apache2\hexoBlogManager</div><div class="line">call hexo clean</div><div class="line">call hexo g</div><div class="line">:hexo s --draft 去掉注释的冒号以发布草稿</div><div class="line">call hexo s</div></pre></td></tr></table></figure>
<h3 id="nginx配置"><a href="#nginx配置" class="headerlink" title="nginx配置"></a>nginx配置</h3><hr>
<p>配置nginx将<a href="http://10.10.10.10/转到hexo网站地址，修改/etx/nginx/nginx.conf，在http模块中添加代理。" target="_blank" rel="external">http://10.10.10.10/转到hexo网站地址，修改/etx/nginx/nginx.conf，在http模块中添加代理。</a><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div></pre></td><td class="code"><pre><div class="line">http &#123;</div><div class="line">		...</div><div class="line">		...</div><div class="line"></div><div class="line">        upstream hexo_blog&#123;</div><div class="line">                ip_hash;</div><div class="line">                server 10.10.10.10:4000;</div><div class="line">                #server 127.0.0.1:8082;</div><div class="line">        &#125;</div><div class="line"></div><div class="line">        # server config</div><div class="line">        server &#123;</div><div class="line">                listen 80;</div><div class="line">                server_name 10.10.10.10 www.bebetter.site bebetter.site;</div><div class="line"></div><div class="line">                location / &#123;</div><div class="line">                        proxy_redirect    off;</div><div class="line">                        proxy_set_header    Host $host;</div><div class="line">                        proxy_set_header    X-Real-IP $remote_addr;</div><div class="line">                        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;</div><div class="line">                        proxy_pass   http://127.0.0.1:4000;</div><div class="line">                &#125;</div><div class="line"></div><div class="line">        &#125;</div><div class="line"></div><div class="line">        include /etc/nginx/conf.d/*.conf;</div><div class="line">        include /etc/nginx/sites-enabled/*;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<h3 id="项目发布"><a href="#项目发布" class="headerlink" title="项目发布"></a>项目发布</h3><hr>
<p>使用<code>hexo s</code>发布项目，使用<code>service nginx start</code>代理网站，访问域名即可。</p>
<p>由于使用ssh访问阿里云服务器，断开ssh的话hexo s会停掉服务，可以使用nohup、screen等方法避免服务停掉。</p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Blog/" rel="tag">#Blog</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/08/08/Blog/搭建个人博客站点1-托管到github pages/" rel="next" title="搭建个人博客站点(1)-托管到github pages">
                <i class="fa fa-chevron-left"></i> 搭建个人博客站点(1)-托管到github pages
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/01/10/Language/Java-basic/Java/" rel="prev" title="Java">
                Java <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    


  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/statics/images/avatar.png"
               alt="gatewayzy" />
          <p class="site-author-name" itemprop="name">gatewayzy</p>
          <p class="site-description motion-element" itemprop="description">blog website with hexo and github pages</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">70</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">10</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              友情链接
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="https://github.com/gatewayzy" title="Github-gatewayzy" target="_blank">Github-gatewayzy</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://google.com/" title="Goolge" target="_blank">Goolge</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://wiki.jikexueyuan.com/" title="Wiki-jike" target="_blank">Wiki-jike</a>
                </li>
              
            </ul>
          </div>
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#参考文章"><span class="nav-number">1.</span> <span class="nav-text">参考文章</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#流程说明"><span class="nav-number">2.</span> <span class="nav-text">流程说明</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#服务器、域名、域名解析"><span class="nav-number">2.1.</span> <span class="nav-text">服务器、域名、域名解析</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#hexo部署网站"><span class="nav-number">2.2.</span> <span class="nav-text">hexo部署网站</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#nginx配置"><span class="nav-number">2.3.</span> <span class="nav-text">nginx配置</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#项目发布"><span class="nav-number">2.4.</span> <span class="nav-text">项目发布</span></a></li></ol></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">gatewayzy</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>

        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  



  




  
  

  
  <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
        processEscapes: true,
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
  </script>

  <script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for (i=0; i < all.length; i += 1) {
        all[i].SourceElement().parentNode.className += ' has-jax';
      }
    });
  </script>
  <script type="text/javascript" src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>



  

  
<script type="text/javascript" async src="//push.zhanzhang.baidu.com/push.js">
</script>


</body>
</html>
